﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class TestSceneVo1 : LoadVo
{
    public override string SceneName
    {
        get
        {
            return "LoadDemo1";
        }
    }
    private int lIndex = 0;
    private int sIndex = 0;
    private List<GameObject> lcubes = new List<GameObject>();
    protected override void OnReleaseLoadData()
    {

    }

    protected override void OnReleaseSceneObject()
    {
        GameObject[] lcs = lcubes.ToArray();
        for (int i = 0; i < lcs.Length; i++)
        {
            if (lcs[i] != null)
            {
                lcs[i].transform.SetParent(LoadingManager.Instance.TempParent);
            }
        }
    }

    protected override void OnStartLoadData(object data)
    {
        lIndex = 0;
    }

    protected override void OnStartLoadSceneObject()
    {

    }

    protected override void OnUpdate()
    {
        switch (m_State)
        {
            case SceneState.LoadingData:
                if (lIndex >= 100)
                {
                    m_IsWorking = false;
                    return;
                }
                lIndex++;
                GameObject go = new GameObject(SceneName + "-l-" + lIndex + ":" + (int)(Time.time * 100));
                go.transform.SetParent(LoadingManager.Instance.TempParent);
                lcubes.Add(go);
                m_LoadDataPrograss = lIndex / 100.0f;
                break;
            case SceneState.LoadSceneObject:
                m_IsWorking = false;
                break;
            case SceneState.ReleaseLoadingData:
                if (lcubes.Count == 0)
                {
                    m_IsWorking = false;
                    return;
                }
                go = lcubes[0];
                lcubes.RemoveAt(0);
                GameObject.Destroy(go);
                m_ReleaseDataPrograss = (100 - lcubes.Count) / 100.0F;
                break;
            case SceneState.ReleaseSceneObject:
                m_IsWorking = false;
                break;
        }
    }
}


public class TestSceneVo2 : LoadVo
{
    public override string SceneName
    {
        get
        {
            return "LoadDemo2";
        }
    }
    private int lIndex = 0;
    private int sIndex = 0;
    private List<GameObject> lcubes = new List<GameObject>();
    protected override void OnReleaseLoadData()
    {

    }

    protected override void OnReleaseSceneObject()
    {
        GameObject[] lcs = lcubes.ToArray();
        for (int i = 0; i < lcs.Length; i++)
        {
            if (lcs[i] != null)
            {
                lcs[i].transform.SetParent(LoadingManager.Instance.TempParent);
            }
        }
    }

    protected override void OnStartLoadData(object data)
    {
        lIndex = 0;
    }

    protected override void OnStartLoadSceneObject()
    {

    }

    protected override void OnUpdate()
    {
        switch (m_State)
        {
            case SceneState.LoadingData:
                if (lIndex >= 100)
                {
                    m_IsWorking = false;
                    return;
                }
                lIndex++;
                GameObject go = new GameObject(SceneName + "-l-" + lIndex + ":" + (int)(Time.time * 100));
                go.transform.SetParent(LoadingManager.Instance.TempParent);
                lcubes.Add(go);
                m_LoadDataPrograss = lIndex / 100.0f;
                break;
            case SceneState.LoadSceneObject:
                m_IsWorking = false;
                break;
            case SceneState.ReleaseLoadingData:
                if (lcubes.Count == 0)
                {
                    m_IsWorking = false;
                    return;
                }
                go = lcubes[0];
                lcubes.RemoveAt(0);
                GameObject.Destroy(go);
                m_ReleaseDataPrograss = (100 - lcubes.Count) / 100.0F;
                break;
            case SceneState.ReleaseSceneObject:
                m_IsWorking = false;
                break;
        }
    }
}
